<!-- 通讯录的列表 -->
<template>
  <div class="contain">
    <app-header></app-header>
    <!--search-->
    <div class="m-sech-wrap mr20">
      <router-link to='/search?type=user' class="m-sech-box displayflex">
        <i class="iconfont icon-search"></i>
        <div class="flex1 m-sech-ipt">
          <div class="txt">{{sechTxt || '输入用户名称'}}</div>
        </div>
      </router-link>
    </div>
     <!--<div class="displayflex con-app-head">
      <div class="flex1">
        <label>
          <input type="checkbox" class="list-radio-check">
          <span class="list-radio-circle pos-list"></span>
          <em class="txt">全选（0）</em>
        </label>
      </div> 
    </div>-->
    <div class='contact-list-wrap'>
      <label class="displayflex contact-list" v-for="item in items">
        <input type="radio" class="list-radio-check" name="card"  :value="item" v-model="selectuseritems">
        <span class="list-radio-circle pos-list"></span>
        <div class="pic"><img src="~images/default/ll.jpg"></div>
        <dl class="flex1 txt">
          <dt>{{item.Name}}</dt>
          <dd>{{item.UserBizType | role}} {{item.MobileNo}}</dd>
        </dl>
      </label>
    </div>
    <!-- <div class="detail-bottom displayflex"> -->
      <!-- <span>已选择（<em class="red">{{selectuseritems.length}}</em>）</span> -->
      <!-- <div class="flex1 btn-grp"> -->
        <!-- <div class="btn">订单分享</div> -->
        <!-- <div class="btn" @click="next" v-if="type=='3'">下一步</div> -->
        <!-- <div class="btn" @click="showDia">确定</div>
      </div>
    </div> -->
    <div class="form-btn" @click="showDia">确定</div>
    <!-- 弹框start -->
    <confirm 
      class="ll-dialog"
      v-model="showRecall"
      title="预约订单"
      @on-cancel="onCancel"
      @on-confirm="onConfirm">
      <div class="dialog-ctx">
        <em>
          <i class="iconfont icon-complete"></i>
          您已成功预约{{billitems.length}}张订单
        </em>
      </div>
    </confirm>
    <!-- 弹框end -->
  </div>
</template>

<script>
import appHeader from '@/components/core/header/app_header.vue';
export default {
  components:{
    appHeader
  },
  name: "choiceMan",
  data() {
    return {
      sechTxt: "",
      showRecall: false,
      items: [],
      billitems: [],
      selectuseritems: [],
      type: ""
    };
  },
  created() {
    this.getData();
    this.billitems = JSON.parse(sessionStorage.items);
    this.type = this.$route.query.type;
    this.sechTxt = sessionStorage.sechtxt;
  },
  methods: {
    onCancel() {},
    onConfirm(msg) {
      this.$router.push({
        path: "/order/appointList",
        query: { type: this.type }
      });
    },
    next() {
      if (this.selectuseritems.length == 0) {
        this.Toast({
          message: "请选择人员"
        });
        return false;
      }
      sessionStorage.selectuseritems = JSON.stringify(this.selectuseritems);
      this.$router.push({
        path: "/order/choiceForm",
        query: { type: this.type }
      });
    },
    showDia() {
      if (this.selectuseritems.length == 0) {
        this.Toast({
          message: "请选择人员"
        });
        return false;
      }
      var self = this;
      sessionStorage.items = JSON.stringify(this.billitems);
      sessionStorage.selectuseritems = JSON.stringify(this.selectuseritems);
      var userinfo = JSON.parse(localStorage.userinfo);
      if (this.type != "4") {
        var query = {
          medpo: self.billitems,
          bespeak: self.selectuseritems,
          CreateUserName: userinfo.StaffID,
          CreateUserId: userinfo.Name,
          BespeakType: self.type
        };
        this.Ajax.post("CreateTRmedpobespeak", query).then(function(resp) {
          if (resp.IsSuccess) {
            self.showRecall = true;
            self.Ajax.post("BespeakGoPush", query).then(function(resp){});// 执行推送
          } else {
            self.Toast({
              message: resp.ErrorMessage || "操作失败，请稍后重试"
            });
          }
        });
      } else {
        this.$router.push({
          path: "/order/choiceform",
          query: { type: this.type, name: "Driver" }
        });
      }
    },
    getData() {
      var self = this;
      var userinfo = JSON.parse(localStorage.userinfo);
      var role = this.$route.query.name;
      var query = {
        TenantGUID: userinfo.TenantGUID,
        CorpGuid: userinfo.CorpGuid,
        Name: sessionStorage.sechtxt || "",
        UserBizType: role,
        StaffID: ""
      };
      this.Ajax.post("SearchMfstaffbacies", query).then(function(resp) {
        if (resp.IsSuccess) {
          //modi by lxf
          var Obj = resp.Datas;
          // Obj.forEach(function(ele, idx) {
          //   if(ele.StaffID == userinfo.StaffID){
          //     Obj.splice(idx, 1);
          //   }
          // }, this);
          self.items = Obj;
          //end modi
        } else {
          self.Toast({
            message: resp.ErrorMessage || "操作失败，请稍后重试"
          });
        }
      });
    }
  }
};
</script>